<template>
  <div>
    <el-button @click.native="refreshList">重新获取数据</el-button>
  </div>
</template>

<script>
  import SelectTree from '@/components/treeSelect/treeSelect.vue'
  import UserSelect from '@/components/userSelect'
  import CityPicker from '@/components/cityPicker'

  export default {
    data () {
      return {
        searchForm: {
          office: {
            id: ''
          },
          tuser: {
            id: ''
          },
          area: '',
          ip: '',
          beginDate: '',
          storeNo: '',
          storeName: '',
          processName: '',
          endDate: '',
          remarks: ''
        },
        dataList: [],
        spanArr: [],
        position: 0,
        pageNo: 1,
        pageSize: 10,
        total: 0,
        orderBy: '',
        dataListSelections: [],
        isSearchCollapse: true,
        isImportCollapse: false,
        loading: false
      }
    },
    components: {
      SelectTree,
      UserSelect,
      CityPicker
    },
    activated () {
    },

    methods: {
      // 获取数据列表
      refreshList () {
        this.loading = true
        this.$http({
          url: '/test/processTime/sendOrder?type=4',
          method: 'get',
          params: {}
        }).then(({data}) =>{
          this.$message.success(data.msg)
        })
      },
    rowspan(idx, prop) {
      this.spanArr[idx] = [] // 存储要合并的数组
      const that = this
      this.position = 0 // 存储要合并的位置
      this.dataList.forEach((item, index) => {
        if (index === 0) {
          that.spanArr[idx].push(1)
          that.position = 0
        } else {
          if (that.dataList[index][prop] === that.dataList[index - 1][prop]) {
            that.spanArr[idx][that.position] += 1 // 有相同项
            that.spanArr[idx].push(0) // 名称相同后往数组里面加一项0
          } else {
            that.spanArr[idx].push(1) // 同列的前后两行单元格不相同
            that.position = index
          }
        }
      })
    },
    objectSpanMethod({row, column, rowIndex, columnIndex}) {
      for (let i = 0; i < this.spanArr.length; i++) {
        if (columnIndex === i) {
          const _row = this.spanArr[i][rowIndex]
          const _col = _row > 0 ? 1 : 0
          return {
            rowspan: _row,
            colspan: _col
          }
        }
      }
    },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageNo = 1
        this.refreshList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageNo = val
        this.refreshList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },

    // 排序
      sortChangeHandle (obj) {
        if (obj.order === 'ascending') {
          this.orderBy = obj.prop + ' asc'
        } else if (obj.order === 'descending') {
          this.orderBy = obj.prop + ' desc'
        } else {
          this.orderBy = ''
        }
        this.refreshList()
      },
      // 新增
      add () {
        this.$refs.leaveFormForm.init('add', '')
      },
      // 修改
      edit (id) {
        id = id || this.dataListSelections.map(item => {
          return item.id
        })[0]
        this.$refs.leaveFormForm.init('edit', id)
      },
      // 查看
      view (id) {
        this.$refs.leaveFormForm.init('view', id)
      },
      // 删除
      del (id) {
        let ids = id || this.dataListSelections.map(item => {
          return item.id
        }).join(',')
        this.$confirm(`确定删除所选项吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          this.$http({
            url: '/test/tobacco/tobaccoForm/delete',
            method: 'delete',
            params: {'ids': ids}
          }).then(({data}) => {
            if (data && data.success) {
              this.$message.success(data.msg)
              this.refreshList()
            }
            this.loading = false
          })
        })
      },
      // 导入成功
      uploadSuccess (res, file) {
        if (res.success) {
          this.$message.success({dangerouslyUseHTMLString: true,
            message: res.msg})
        } else {
          this.$message.error(res.msg)
        }
      },
      // 下载模板
      downloadTpl () {
        this.$utils.download('/test/tobacco/tobaccoForm/import/template')
      },
      exportExcel () {
        this.$utils.download('/test/tobacco/tobaccoForm/export')
      },
      resetSearch () {
        this.$refs.searchForm.resetFields()
        this.refreshList()
      }
    }
  }
</script>
